package com.tql.view.controller;

import com.tql.view.pojo.Notice;
import com.tql.view.pojo.Scenery;
import com.tql.view.pojo.User;
import com.tql.view.service.UserService;
import com.tql.view.util.DowLoadUtil;
import com.tql.view.util.FileDownloadUtil;
import com.tql.view.util.JsonUtil;
import com.tql.view.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.*;

@Controller
public class test {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private UserService userService;
    @Autowired
    private DowLoadUtil dowLoadUtil;
  /*  //输入关键字
    private static String antistop="美女";*/
    //编码关键字
    private static String encode;
  /*  private static int i=1;*/
    private static int name = 1;
    private static InputStream inputStream = null;
    private static FileOutputStream outputStream = null;
    //下载路径
    private static String path="E:\\view\\";
    //删除文件数量
    private static int c = 0;
    //下载图片的颜色
    private static String color = "0";
    //下载图片尺寸
 /*   private static String size = "9";*/
    @RequestMapping(value="/download")
    public void downloadFile(@RequestParam("location")String location, HttpServletResponse response, HttpServletRequest request){
       String sub= UUID.randomUUID()+"A";
        String url="http://localhost:8081"+location;
        String path1="E:/view/myimage/"+sub+".jpg";
        FileDownloadUtil.downloadPicture(url,path1);
    }
    @RequestMapping("/testurl")
    public String testUrl(){
        return "view/backgroud";
    }
    @RequestMapping("/test77")
    public String test77(){
        return "admin/adminMain1";
    }
    @RequestMapping("/tospider")
    public String toSpider(){
        return "admin/spider";
    }
    @RequestMapping("/spider")
    @ResponseBody
    public String Spider(@RequestParam("antistop")String antistop,
                       @RequestParam("page") String page,
                       @RequestParam("size") String size,
                         @RequestParam("type") String type) throws InterruptedException {
        String path1=path+type;
        try {
            dowLoadUtil.commandLineDownload(antistop,encode,outputStream,inputStream,path1,size,color,name,c,Integer.parseInt(page));
        }catch (Exception e){
            e.printStackTrace();
        }
        return antistop+"------"+page+"---------"+size;
    }
    @RequestMapping("/test11")
    @ResponseBody
    public String test11(String myurl){
        String my=myurl;
        return my;
    }
    @RequestMapping("/testa1")
    @ResponseBody
    public String test11(){
        User user=new User("hello","hello","hello","heloo","admin","jfjfjf","jjj",0,"hell");
        User user1=new User("sir","hello","hello","heloo","admin","jfjfjf","jjj",0,"hell");
        redisUtil.lpush("hello11",user);
        redisUtil.lpush("hello11",user1);
        return "hello";
    }
    @RequestMapping("/testa2")
    @ResponseBody
    public String test12(){
        User user=new User("hello","hello","hello","heloo","admin","jfjfjf","jjj",0,"hell");
        redisUtil.lRemove("hello11",1,user);
        return "kfjakhglag";
    }


}
